package dominion.model.actions.base;

import java.util.List;

import dominion.model.Card;
import dominion.model.GameBoard;
import dominion.model.Player;
import dominion.model.actions.Action;
import dominion.utils.Constants;

public class Witch extends Action {

	public Witch() {
		cost = 5;
	}

	@Override
	public Card clone() {
		return new Witch();
	}

	@Override
	public String toString() {
		return "Witch";
	}

	@Override
	public String getDescription() {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDescription());
		sb.append("+2 Cards.\n");
		sb.append("Each other player gains a curse card.\n");
		return sb.toString();
	}

	@Override
	public void doAction(Player player, GameBoard board, List<Player> players) {
		player.changeAction(-1);
		player.drawCard();
		player.drawCard();

		for (Player target : players)
		{
			if (target.equals(player))
			{
				continue;
			}
			if (target.hasCounter())
			{
				Constants.printer.print(target.getName() + " has a Moat and is unaffected.");
				continue;
			}
			Card card = board.drawFromCurses();
			if (card == null)
			{
				Constants.printer.print("No more curses left.");
			}
			else
			{
				target.addToDeck(card, Constants.DISCARD_DECK);
			}
		}

		playedCard(player);
		Constants.printer.print("New Hand: ");
		Constants.printer.print(player.printHand());
	}
}
